#include "stdafx.h"
#include "vector.h"

Vector::Vector(int first_index, int number)
:i1(first_index), num(number)
{
	assert(num >= 0);
	p = new int[num];
}

int Vector::read(int index)
{
	assert(index >= i1 && index <= last());
	return p[index - i1];
}

void Vector::change(int index, int value)
{
	assert(index >= i1 && index <= last());
	p[index - i1] = value;
}

Vector::Vector(const Vector& v)
:i1(v.i1), num(v.num)
{
	p = new int[num];
	for (int i = 0; i< num ;i++)
	{
		p[i] = v.p[i];
	}
}

bool Vector::operator==(const Vector& v)const
{
	if (num != v.num)
	{
		return false;
	}
	for (int i = 0; i< num; i++)
	{
		if (p[i] != v.p[i])
		{
			return false;
		}
	}

	return true;
}

bool Vector::operator!=(const Vector& v)const
{
	return !( (*this) == v);
}

const Vector& Vector::operator+=(const Vector& v)
{
	assert(num == v.num);
	for (int i = 0; i<num; i++)
	{
		p[i] += v.p[i];
	}
	return *this;
}

Vector Vector::operator+(const Vector& v)const
{
	assert(num == v.num);
	Vector temp(*this);
	temp += v;
	return temp;
}

const Vector Vector::operator+=(int d)
{
	for (int i = 0; i< num ; i++)
	{
		p[i]+= d;
	}
	return *this;
}

Vector Vector::operator+( int d) const
{
	Vector temp(*this);
	temp+=d;
	return temp;
}